package com.platform.core.web.controller;

import cn.hutool.core.bean.BeanUtil;
import com.platform.comm.web.results.DataJsonResult;
import com.platform.comm.web.results.JsonResult;
import com.platform.comm.web.results.PageListJsonResult;
import com.platform.core.service.NcloudSysNameStandardService;
import com.platform.dto.NcloudSysNameStandardDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import static com.platform.controller.BaseController.getPageable;

/**
 * Description: ncloud_sys_name_standard-管理接口
 *
 * @author Coder
 */
@RestController
@RequestMapping(name = "ncloud_sys_name_standard管理", path = "/management/ncloudSysNameStandard")
public class NcloudSysNameStandardController {

    private final NcloudSysNameStandardService ncloudSysNameStandardService;

    @Autowired
    public NcloudSysNameStandardController(NcloudSysNameStandardService ncloudSysNameStandardService) {
        this.ncloudSysNameStandardService = ncloudSysNameStandardService;
    }

    /**
     * 查询命名规范信息列表Page
     */
    @PostMapping(name = "查询命名规范信息列表,返回page", path = "/searchByExampleForPage")
    public PageListJsonResult<NcloudSysNameStandardDto> searchByExampleForPage(@RequestBody Map<String, Object> paramsMap) {
        Page<NcloudSysNameStandardDto> entities = ncloudSysNameStandardService.searchByExampleForPage(
                BeanUtil.toBeanIgnoreCase(paramsMap, NcloudSysNameStandardDto.class, false), getPageable(paramsMap));
        return new PageListJsonResult<>(entities);
    }

    /**
     * 查询命名规范信息列表List
     */
    @PostMapping(name = "查询命名规范信息列表,返回list", path = "/searchByExampleForList")
    public DataJsonResult<List<NcloudSysNameStandardDto>> searchByExampleForList(@RequestBody NcloudSysNameStandardDto ncloudSysNameStandardDto) {
        return DataJsonResult.succeed(ncloudSysNameStandardService.searchByExampleForList(ncloudSysNameStandardDto));
    }

    /**
     * 查询命名规范明细数据
     */
    @PostMapping(name = "查询命名规范明细数据", path = "/detail")
    public DataJsonResult<NcloudSysNameStandardDto> detail(@RequestBody Map<String, String> param) {
        return DataJsonResult.succeed(ncloudSysNameStandardService.detail(param.getOrDefault("id", null)));
    }

    /**
     * 新增命名规范信息表
     */
    @PostMapping(name = "新增命名规范信息表", path = "/add")
    public JsonResult add(@RequestBody NcloudSysNameStandardDto ncloudSysNameStandardDto) {
        ncloudSysNameStandardService.add(ncloudSysNameStandardDto);
        return JsonResult.success();
    }

    /**
     * 修改命名规范信息表数据
     */
    @PostMapping(name = "修改命名规范信息表", path = "/update")
    public JsonResult update(@RequestBody NcloudSysNameStandardDto ncloudSysNameStandardDto) {
        ncloudSysNameStandardService.update(ncloudSysNameStandardDto);
        return JsonResult.success();
    }

    /**
     * 删除命名规范信息表
     */
    @PostMapping(name = "删除命名规范信息表", path = "/delete")
    public JsonResult delete(@RequestBody Map<String, String> param) {
        ncloudSysNameStandardService.remove(param.getOrDefault("id", null));
        return JsonResult.success();
    }

    /**
     * 进行校验名称不能重复
     */
    @PostMapping(name = "进行校验名称不能重复", path = "/checkByName")
    public DataJsonResult<Boolean> checkByName(@RequestBody NcloudSysNameStandardDto ncloudSysNameStandardDto) {
        return DataJsonResult.succeed(ncloudSysNameStandardService.checkByName(ncloudSysNameStandardDto));
    }
}
